<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
</head>
<body>

<p>整数1： <input type="text" id="num1"></p>
<p>整数2： <input type="text" id="num2"></p>
<p> <button onclick="ab('+')">相加</button>
    <button onclick="ab('-')">相减</button>
    <button onclick="ab('*')">相乘</button>
    <button onclick="ab('/')">相除</button></p>
<p>结果： <input type="text" id="num3"></p>

<script>
    function ab(n) {
        var num1 = document.querySelector("#num1").value;
        var num2 = document.querySelector("#num2").value;
        num1 = Number(num1);   //字符串
        num2 = Number(num2);  //转数字
        var result = 0;
        switch(n) {
            case "+":
                result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                result = num1 / num2;
                break;

        }
        document.querySelector("#num3").value=result;
    }
</script>


</body>
</html>